package src.IO特殊操作流;

import java.io.*;

/*
* ObjectInputStream 反序列化优先使用ObjectOutputStream编写的原始数据和对象
* ObjectInputStream(InputStream in) 创建从指定的InputStream读取的ObjectInputStream
* 反序列化对象的方法 Object readObject() 从ObjectInputStream读取一个对象
* */
public class 对象反序列化流 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day10\\oos.txt"));
        Object obj = ois.readObject();
        Student2 s = new Student2();
        System.out.println(s.getName()+","+s.getAge());
        ois.close();
    }
}

/*
 * 学生类
 * */
class Student2 implements Serializable {
    private String name;
    private int age;
    public Student2(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public Student2() {
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    @Override
    public String toString() {
        return "Student1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}